<?php

namespace app\admin\controller;

use app\BaseController;
class Admin extends BaseController
{

//    管理员登陆
    public function login(){
        $username = $this->request->param('username', '', 'trim');
        $password = $this->request->param('password', '', 'trim');
        $data = [
            'username' => $username,
            'password' => $password,
        ];
        //        TP6检验机制
//        try {
//            validate(\app\admin\validate\Admin::class)->scene('username')->check($data);
//        } catch (\think\exception\ValidateException $e) {
//            return show(config('status.error'), $e->getError());
//        }
        try {
            $adminObj = new \app\common\business\Admin();
            $result = $adminObj->login($data);
            return show(config('common.http_status.success'), '登录成功',$result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    //    退出登录
    public function logout(){
        $id = ($this->request->userInfo)['id'];
        $token = $this->request->token;
        try {
            $adminObj = new \app\common\business\Admin();
            $result = $adminObj->logout($id,$token);
            return show(config('common.http_status.success'), '退出登录',$result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }
}